home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NETWORK.SWG / 0014_Novell User Name 2.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  91 lines

  1. {
  2. > I need a way to get the current user name from the netware shell.
  3. > For instance, if I'm logged into server MYSERVER as user SUPERVISOR,
  4. > I need some way to get 'supervisor' as the user name...
  5.  
  6. This should do the job.  The two calls are "Get Connection Number" (DCh) and
  7. "Get Connection Information" (E3h 16h), both from the Connection Services API.
  8. The calls work with Advanced Netware 1.0 and all later versions.  Code tested
  9. on 3.11 NetWare.
  10.  
  11. Beware the weak error-checking - the program doesn't check the version of
  12. Netware, or even that the user is logged onto the network.
  13. }
  14.  
  15. program WhoBeMe;
  16.  
  17. uses Dos;
  18.  
  19.  
  20. procedure GetUserName( var UserName : string );
  21.  
  22. var
  23.   Request : record                     { Request buffer for "Get Conn Info" }
  24.     Len  : Word;                       { Buffer length - 2                  }
  25.     Func : Byte;                       { Subfunction number ( = $16 )       }
  26.     Conn : Byte                        { Connection number to be researched }
  27.   end;
  28.  
  29.   Reply    : record                    { Reply buffer for "Get Conn Info"   }
  30.     Len    : Word;                     { Buffer length - 2                  }
  31.     ID     : Longint;                  { Object ID (hi-lo order)            }
  32.     Obj    : Word;                     { Object type (hi-lo order again)    }
  33.     Name   : array[ 1..48 ] of Byte;   { Object name as ASCII string        }
  34.     Time   : array[ 1.. 7 ] of Byte;   { Y, M, D, Hr, Min, Sec, DOW         }
  35.                                        { Y < 80 is in the next century      }
  36.                                        { DOW = 0 -> 6, Sunday -> Saturday   }
  37.     Filler : Byte                      { Call screws up without this!       }
  38.   end;
  39.  
  40.   Regs   : Registers;
  41.   W      : Word;
  42.  
  43. begin
  44.   Regs.AX := $DC00;                    { "Get Connection Number"            }
  45.   MsDos( Regs );
  46.                                        { "Get Connection Information"       }
  47.  
  48.   with Request do                      { Initialize request buffer:         }
  49.   begin
  50.     Len := 2;                                    { Buffer length,           }
  51.     Func := $16;                                 { API function,            }
  52.     Conn := Regs.AL                    { Returned in previous call!         }
  53.   end;
  54.  
  55.   Reply.Len := SizeOf( Reply ) - 2;    { Initialize reply buffer length     }
  56.  
  57.   with Regs do
  58.   begin
  59.     AH := $E3;                         { Connection Services API call       }
  60.     DS := Seg( Request );              { Location of request buffer         }
  61.     SI := Ofs( Request );
  62.     ES := Seg( Reply );                { Location of reply buffer           }
  63.     DI := Ofs( Reply );
  64.     MsDos( Regs )
  65.   end;
  66.  
  67.   if ( Regs.AL = 0 )                        { Success code returned in AL   }
  68.        and ( Hi( Reply.Obj ) = 1 )          { Obj of 1 is a user,           }
  69.        and ( Lo( Reply.Obj ) = 0 ) then     {   stored Hi-Lo                }
  70.     with Reply do
  71.     begin
  72.       Move( Name, UserName[ 1 ], 48 );           { Convert ASCIIZ to string }
  73.       UserName[ 0 ] := #48;
  74.       W := 1;
  75.       while ( UserName[ W ] <> #0 )
  76.             and ( W < 48 ) do
  77.         Inc( W );
  78.       UserName[ 0 ] := Char( W - 1 )
  79.     end
  80.   else
  81.     UserName := ''
  82. end;
  83.  
  84. var
  85.   TheName : string;
  86.  
  87. begin
  88.   GetUserName( TheName );
  89.   WriteLn( 'I be ', TheName )
  90. end.
  91.